﻿Imports System.Resources
Imports System.Threading
Imports System.Configuration
Imports Biz
Imports BLL
Imports System.IO


Partial Friend Class Main

    Public Shared Sub Main()

        Application.EnableVisualStyles()

        frmMainMetro.Inicializar()

        frmMainMetro.WindowState = FormWindowState.Maximized
        frmMainMetro.BringToFront()

        frmMainMetro.Mostrar()

        Application.Run()

    End Sub

    Public Shared Sub ManejarExcepcion(ByVal ex As Exception)
        Dim rutaLog As String
        Dim strErrorLinea As String
        Dim archiv As StreamWriter


        If (TypeOf ex Is Excepciones.ExceptionManager) Then
            Dim excep = DirectCast(ex, Excepciones.ExceptionManager)
            Try
                MsgBox(excep.mensaje, excep.tipo)
            Catch e As Excepciones.ExcepcionNoEncontradaExcepcion
                ManejarExcepcion(e)
            End Try

            Try
                rutaLog = My.Application.Info.DirectoryPath + "\ErroresBusquedasLab.log"

                archiv = New StreamWriter(rutaLog, True)

                strErrorLinea = "-----INICIO DE LA EXCEPCION-----"
                archiv.WriteLine(strErrorLinea)

                strErrorLinea = "Fecha:" + Date.Now
                archiv.WriteLine(strErrorLinea)

                strErrorLinea = "Detalle de la excepción: " + excep.Message
                archiv.WriteLine(strErrorLinea)

                If Not excep.innerException2 Is Nothing Then
                    strErrorLinea = "Inner exception"
                    archiv.WriteLine(strErrorLinea)

                    strErrorLinea = "Stack message:"
                    archiv.WriteLine(strErrorLinea)

                    strErrorLinea = excep.innerException2.Message
                    archiv.WriteLine(strErrorLinea)

                    strErrorLinea = "Source:"
                    archiv.WriteLine(strErrorLinea)

                    strErrorLinea = excep.innerException2.Source
                    archiv.WriteLine(strErrorLinea)

                    strErrorLinea = "HelpLink:"
                    archiv.WriteLine(strErrorLinea)

                    strErrorLinea = excep.innerException2.HelpLink
                    archiv.WriteLine(strErrorLinea)

                    strErrorLinea = "StackTrace:"
                    archiv.WriteLine(strErrorLinea)

                    strErrorLinea = excep.innerException2.StackTrace
                    archiv.WriteLine(strErrorLinea)

                    strErrorLinea = "TargetSite:"
                    archiv.WriteLine(strErrorLinea)

                    strErrorLinea = excep.innerException2.TargetSite.ToString
                    archiv.WriteLine(strErrorLinea)
                End If

                strErrorLinea = "-----FIN DE LA EXCEPCION-----"
                archiv.WriteLine(strErrorLinea)

                strErrorLinea = ""
                archiv.WriteLine(strErrorLinea)

                archiv.Close()

            Catch e As Exception
                MsgBox("Error no controlado: " & e.Message)
            End Try
        Else
            MsgBox("Error no controlado: " & ex.Message)
        End If
        
    End Sub

End Class
